package com.javen.springbootneo4j.service.impl;

import com.javen.springbootneo4j.entity.node.City;
import com.javen.springbootneo4j.repository.CityRepository;
import com.javen.springbootneo4j.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description: com.javen.springbootneo4j.service.impl
 * @Author: tujw@netinnet.cn
 * @Date: 2024/2/28 13:48
 */
@Service
public class CityServiceImpl implements CityService {

    @Autowired
    private CityRepository cityRepository;

    @Override
    public City saveCity(City city) {
        return cityRepository.save(city);
    }

    @Override
    public City getCity(City city) {
        return cityRepository.findByName(city.getName()).orElse(null);
    }

    @Override
    public void updateById(Long id) {
        City city = cityRepository.findById(id).orElse(null);
        if (Objects.isNull(city)) {
            return;
        }
        city.setName("哈尔滨");
        cityRepository.save(city);
    }

    @Override
    public void deleteById(Long id) {
        cityRepository.deleteById(id);
    }

    // 其他业务逻辑...

}
